# -*- coding: utf-8 -*-
from datetime import timedelta
from spmi.dwd.spmi.dwd_spmi_transfer_change_fee_bill_base_dt import spmi_dwd__dwd_spmi_transfer_change_fee_bill_base_dt
from spmi.dim.spmi.jms_dim_network_whole_massage_check import jms_dim__dim_network_whole_massage_check
from spmi.dim.spmi.dim_ibk_sz_bill_config_base import spmi_dim__dim_ibk_sz_bill_config_base
from spmi.dim.spmi.dim_ibk_increase_product_config_base import spmi_dim__dim_ibk_increase_product_config_base
from spmi.dim.spmi.dim_ibk_network_cost_control_center_base import spmi_dim__dim_ibk_network_cost_control_center_base
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

spmi_dwd__dwd_transfer_change_daily_detail_dt = SparkSqlOperator(
    task_id='spmi_dwd__dwd_transfer_change_daily_detail_dt',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='spmi_dwd__dwd_transfer_change_daily_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi/dwd/spmi/dwd_transfer_change_daily_detail_dt/execute.sql',
    pool_slots=2,
    driver_cores=2 , 
    driver_memory='4G' , 
    executor_cores=2 , 
    executor_memory='4G' , 
    num_executors=10 , 
    conf={'spark.dynamicAllocation.enabled'                  : 'true',
          'spark.shuffle.service.enabled'                    : 'true',
        'spark.dynamicAllocation.maxExecutors'             : 12 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 400,
        'spark.executor.memoryOverhead'             : '2G' , 
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 300,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 300,  # 最大分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=50),
    retries=0,
)

spmi_dwd__dwd_transfer_change_daily_detail_dt << [
    spmi_dwd__dwd_spmi_transfer_change_fee_bill_base_dt,
    jms_dim__dim_network_whole_massage_check,
    spmi_dim__dim_ibk_sz_bill_config_base,
    spmi_dim__dim_ibk_network_cost_control_center_base,
    spmi_dim__dim_ibk_increase_product_config_base
]